(ns jna.mekit
  (:use jna))

; Currently, this is Windows only. Probably should be put under jna.win

(def-jna-struct WorkingSet
  [:LONGLONG :Total]
  [:LONGLONG :Private]
  [:LONGLONG :Shared])

(defjna64 Long mekit++ GetProcessWorkingSet)
(defjna64 Long mekit++ FastGetProcessWorkingSet)

(defn get-process-working-set [pid]
  (let [ws (jna-struct-new WorkingSet)]
    (FastGetProcessWorkingSet (int pid) (byref ws))
    {:total (jna-struct-get :Total ws)
     :private (jna-struct-get :Private ws)
     :shared (jna-struct-get :Shared ws)}))

;; Win::GuiTest

(defjna64 Void mekit++ SendKeysImp)

(defn SendKeys
  ([keys delay]
    (SendKeysImp (com.sun.jna.WString. keys) (int delay)))
  ([keys]
    (SendKeys keys 50)))

;; AutoIt

; http://www.autoitscript.com/autoit3/docs/functions/MouseGetCursor.htm
; MouseGetCursor
; Returns the cursor ID Number for the current Mouse Cursor.
;
; *Parameters*
; None.
; *Return Value*
; Returns a cursor ID Number:
;     0 = UNKNOWN (this includes pointing and grabbing hand icons)
;     1 = APPSTARTING
;     2 = ARROW
;     3 = CROSS
;     4 = HELP
;     5 = IBEAM
;     6 = ICON
;     7 = NO
;     8 = SIZE
;     9 = SIZEALL
;   10 = SIZENESW
;   11 = SIZENS
;   12 = SIZENWSE
;   13 = SIZEWE
;   14 = UPARROW
;   15 = WAIT
;   16 = HAND
(defjna64 Integer mekit++ MouseGetCursor)

(defn get-cursor-status []
  ({ 0 :UNKNOWN
     1 :APPSTARTING
     2 :ARROW
     3 :CROSS
     4 :HELP
     5 :IBEAM
     6 :ICON
     7 :NO
     8 :SIZE
     9 :SIZEALL
    10 :SIZENESW
    11 :SIZENS
    12 :SIZENWSE
    13 :SIZEWE
    14 :UPARROW
    15 :WAIT
    16 :HAND} (MouseGetCursor)))

(defjna64 :HANDLE mekit++ GetCursorHandler)

(defn get-cursor-handler []
  (GetCursorHandler))

(defn get-cursor []
  (let [status (get-cursor-status)]
    (if (= status :UNKNOWN)
      (get-cursor-handler)
      status)))
